//
//  LGHomeViewController.m
//  ligenyun
//
//  Created by apple on 2018/3/23.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGHomeViewController.h"
#import "LGHomeHeaderView.h"
#import "LGHomeTableViewCell.h"
#import "LGGongJiDetailViewController.h"


#import "LGSijiHomeViewController.h"
#import "LGGongJiViewController.h"
#import "LGCiTangHomeViewController.h"
#import "LGCultureHomeViewController.h"
#import "LGFindGenViewController.h"
#import "LGJiaPuHomeViewController.h"
#import "LGFamliyTreeHomeViewController.h"
#import "LGCemeteryHomeViewController.h"
#import "LGTodayJiSiViewController.h"
@interface LGHomeViewController ()<LGHomeHeaderViewDelegate>
@property(nonatomic, strong) LGHomeHeaderView     *header;
@property(nonatomic, strong) NSMutableArray     *dataSouce;
@end

@implementation LGHomeViewController

#pragma mark --vc生命周期

- (void)viewDidLoad{
    [super viewDidLoad];
    self.header = [[LGHomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    self.header.delegate = self;
    self.tableView.tableHeaderView = self.header;
    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.frame = CGRectMake(0, 0, UIScreenWidth, [TMUtils tabBarTop]  );
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self st_hideNavagetionbarAnimated:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self st_showNavagationbarAnimated:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10   ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 44;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * view = [TMUtils headerViewWithTitle:@"推荐陵园"];
    STButton * moreButton = [[STButton alloc] initWithFrame:CGRectMake(0, 5, 65, 34)
                                                      title:@"更多 >"
                                                 titleColor:[UIColor whiteColor]
                                                  titleFont:10
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:[UIImage imageNamed:@"双击替换元素1"]
                                                      image:nil];
    [view addSubview:moreButton];
    moreButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    moreButton.right = UIScreenWidth - 15;
    return view;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%lu",indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryNone;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.navigationController pushViewController:[LGGongJiDetailViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method

- (void)onSelctedMoreButton{
    
}
#pragma mark --LGHomeHeaderViewDelegate
- (void)onslectedResbonderWithTitle:(NSString*)title{
    if ([title isEqualToString:@"私祭"]) {
        LGSijiHomeViewController * vc = [LGSijiHomeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"公祭"]) {
        LGGongJiViewController * vc = [LGGongJiViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"祠堂"]) {
        LGCiTangHomeViewController * vc = [LGCiTangHomeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"礼根文化"]) {
        LGCultureHomeViewController * vc = [LGCultureHomeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"寻根"]) {
        LGFindGenViewController * vc = [LGFindGenViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"家谱"]) {
        LGJiaPuHomeViewController * vc = [LGJiaPuHomeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"家庭树"]) {
        LGFamliyTreeHomeViewController * vc = [LGFamliyTreeHomeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"陵园墓地"]) {
        LGCemeteryHomeViewController * vc = [LGCemeteryHomeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([title isEqualToString:@"今日祭祀"]) {
        LGTodayJiSiViewController * vc = [LGTodayJiSiViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
#if debug
//    NSMutableDictionary * dic = [NSMutableDictionary new];
//    NSString * test;
//    [dic setObject:test forKey:@"crash"];
#endif
}
- (void)onslectedBannerWithIndex:(NSInteger)index{
    
}
@end
